package com.sdtele.tta.operation;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sdtele.tta.dac.Dac;
import com.sdtele.tta.models.JsonRequest;
import com.sdtele.tta.models.JsonResponse;

import com.sdtele.tta.models.TaskResponse;
import com.sdtele.tta.models.User;

public class OperationGetFeedBack extends Operation {

	public JsonResponse handle(JsonRequest jsonRequest) {
		System.out.println("OperationLogin:req=" + jsonRequest);
		JsonResponse jres = new JsonResponse();
		User user = (User) request.getSession().getAttribute("user");
		long taskId = jsonRequest.getJsonObject().get("taskId").getAsLong();
		
		if (user != null)

		{	    List<Map<String,Object>> mapList = new ArrayList <Map<String,Object>> ();
				List <TaskResponse> feedBackList = Dac.getInstance().getResponse(taskId);
				if(feedBackList != null)
				{
					for (TaskResponse feedBack :feedBackList)
					{
						Map<String,Object> map = new HashMap<String,Object>();
						map.put("feedBack", feedBack.ToTaskResponse());
						User feedBackUser = Dac.getInstance().getUser(feedBack.getUserId());
						map.put("feedBackUser", feedBackUser);
						mapList.add(map);
					}
					
					jres.setStatus(0);
					jres.setMessage("任务反馈信息列表");
					jres.setEntity(mapList);
				}else
				{
					jres.setStatus(0);
					jres.setMessage("无任何反馈");
					jres.setEntity("");
				}
		    	
		    
			}else
			{
				jres.setStatus(1);
				jres.setMessage("用户不在有效期");
			}
			
		
		return jres;

	}

}